package com.qiyuan.boot.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qiyuan.boot.web.bean.BlogCarousel;
import com.qiyuan.boot.web.service.CarouselService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  图片轮播
 * </p>
 *
 * @author qiyuan
 * @since 2022-03-11
 */
@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Resource
    private CarouselService carouselService;

    /**
     * 分页查询
     */
    @GetMapping("/list")
    public HashMap<String, Object> getArticlePage(Integer  pageSize, Integer currentPage){
        HashMap<String,Object> result = new HashMap<>();
        if (pageSize != null && currentPage != null){
            PageHelper.startPage(currentPage, pageSize);
            List<BlogCarousel> carouselList= carouselService.selectList();
            PageInfo<BlogCarousel> pageInfo = new PageInfo<>(carouselList);
            result.put("data",pageInfo);
        }else {
            List<BlogCarousel>  carouselList= carouselService.selectList();
            result.put("data",carouselList);
        }
        return result;
    }

}
